package com.ljs.tranctionldemo.Controller;

import com.ljs.tranctionldemo.bean.Mongo;
import com.ljs.tranctionldemo.bean.Users;
import com.ljs.tranctionldemo.request.MoneyRequest;
import com.ljs.tranctionldemo.service.MongoService;
import com.ljs.tranctionldemo.service.UserService;
import com.ljs.tranctionldemo.util.BasePageResult;
import com.ljs.tranctionldemo.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: liujinsheng
 * @Date: 2021/6/28.
 */
@RestController
public class UsersController {
    @Resource
    UserService userService;
    @Resource
    MongoService mongoService;
    @PostMapping("/add")
    public Boolean add(@RequestBody Users users){
        return userService.add(users);
    }
    @GetMapping("/findAll")
    public Result<BasePageResult<List<Users>>> findAll(@RequestParam("page") int page,@RequestParam("size") int size){
        return userService.findAll(page,size);
    }
    @PostMapping("/delete/{id}")
    public  Boolean delete(@PathVariable("id") String id){
        return  userService.delete(id);
    }
    @PostMapping("/update")
    public Boolean update(@RequestBody Users users){
        return  userService.update(users);

    }
    @GetMapping("/findById")
    public Users findById(String id) {
        return userService.findById(id);
    }
    /**
     * 转账
     */

    @PostMapping("/trans")
    public Result trans(@RequestBody MoneyRequest moneyRequest) {
        System.out.println("对象是"+moneyRequest);
        return  userService.trans(moneyRequest.getToId(),moneyRequest.getInId(),moneyRequest.getMoney());
    }
     @PostMapping("/mongo/add")
    public void add( @RequestBody Mongo mongo){

         mongoService.add(mongo);
    }
}
